package 乙级;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 * @author mubei
 * @date 2021/8/20
 * @description
 */
public class 验查身份证 {

    public static void main(String[] args) {
        HashMap<Integer, Character> map = new HashMap<Integer, Character>();
        int[] Z = {0,1,2,3,4,5,6,7,8,9,10};
        char[] M = {'1','0','X','9','8','7','6','5','4','3','2'};
        int[] weight = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
        for (int i = 0; i < Z.length; i++) {
            map.put(Z[i],M[i]);
        }

        Scanner scanner = new Scanner(System.in);
        int n =scanner.nextInt();

        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < n; i++) {
            String str = scanner.next();
            String substring = str.substring(0, 17);
            try{
                Long i1 = Long.parseLong(substring);
                char[] chars = substring.toCharArray();
                int sum = 0;
                for (int j = 0; j < chars.length; j++) {
                    sum += (chars[j] - '0')*weight[j];
                }
                Character character = map.get(sum % 11);
                if(character!=str.charAt(17)){
                    list.add(str);
                }
            }catch(Exception e){
                list.add(str);
            }
        }

        if(list.size()==0){
            System.out.println("All passed");
        }else{
            for (int i = 0; i < list.size(); i++) {
                System.out.println(list.get(i));
            }
        }


    }

}
